package com.miot.im.listener;

import com.miot.im.cache.MiotCache;
import com.miot.im.netty.vsp.NotifyMessageExpandListenerInterface;
import com.miot.im.util.DecodeUtil;
import org.apache.log4j.Logger;

import java.io.UnsupportedEncodingException;
import java.util.Map;

public class TestMessageListener implements
		NotifyMessageExpandListenerInterface {
	static Logger log = Logger.getLogger(TestMessageListener.class);
	@Override
	public void connectPlatformResult(int connectResult) {
		log.info("connectResult = " + connectResult);
		if (connectResult == LOGIN_SUCCESS) {
			log.info("login success ! connectResult = " + connectResult);
		} else if (connectResult == LOGIN_FAIL) {
			log.info("登陆失败");
		} else if (connectResult == RECONNECT) {
			log.info("开始断线重连");
		} else if (connectResult == ENFORCE_LOGOUT) {
			log.info("账号强制退出，异地登陆");
		} else if (connectResult == LOGOUT) {
			log.info("账号登出");
		}
	}

	@Override
	public void receiveUartData(int puId, String uartData) {
		System.out.println("receiveUartData--> puId:" + puId + ",uartData=" + uartData);
		System.out.println("receiveUartData hexToByte--> " + DecodeUtil.hexToDec(uartData));

		MiotCache.dataCacheArray=DecodeUtil.hexToDec(uartData);
	}

	@Override
	public void notifyPuState(int puId, int state, int sequence) {
		System.out.println("notifyPuState--> puId:" + puId + ",state:" + state + ",sequence:"
				+ sequence);
	}

	@Deprecated
	@Override
	public void notifyCu2Cu(int cuId, String data) {
	}

	@Override
	public void receiveUartData(int puId, byte[] uartDateBytes) {
		System.out.println("puId:" + puId);
		try {
			System.out.println("uartDates:"
					+ new String(uartDateBytes, "ISO-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void notifyGetLocationAck(int arg0, Map<String, String> arg1) {
		// TODO Auto-generated method stub
	}
}
